<?php namespace App\Http\Controllers\user\uc\ass;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Controllers\user\uc\CommonController;
use Illuminate\Http\Request;
use Validator;
use Input;
use App\Models\AssociationBase;
use App;
use App\Models\Users;
use Session;

class ValidatorController extends Controller {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */

	public function __construct()
	{
		$this->middleware('isattestation');
	}
	
	public function index()
	{
		$type = env('ASSOCIATION');
		return view("user.uc.ass.add_groupinfo")->withSitePos("基本信息")->withParentPos($this->getRoleName($type))->withType($type)->withProvinces(CommonController::getAllProvince()->toArray());
	}

	public function addGroupInfo()
	{
		$rule = [];
		$msg = [];
		$validator = Validator::make(Input::all(), $rule, $msg);
		if($validator->passes())
		{
			$uid = $this->getUid();
			$model = AssociationBase::where("uid", $uid);
			if(!$model->count())
			{
				$data = Input::all();
				$imgArr = Input::only("regist_copy", "logo");
				$this->moveImages($imgArr, env("OTHERS_DIR"));
				$data["uid"] = $uid;
				AssociationBase::create($data);
				Users::where("id", $uid)->update(["role_id" => env("ASSOCIATION")]);
				$uSession = Users::with(['profile'])->where("id", $uid)->get()[0]->toArray();
				Session::put("user", $uSession);
				return $this->json([]);
			}
			else
			{
				return;
			}
		}
		else
		{
			$errors = $validator->messages();
			return self::error($errors->first());
		}

	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		//
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		//
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}

}
